package org.kabeja.dxf.entity;

import org.kabeja.dxf.DXFDocument;
import org.kabeja.dxf.helpers.Point;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author shutao
 * @since 2022/4/24 17:22
 */
public class DXFBlock {
    public static String TYPE = "BLOCK";
    private Point referencePoint = new Point();
    private String layerID = "0";
    private String name = "";
    private String description = "";
    private final List<DXFEntity> entities = new ArrayList<>();
    private DXFDocument doc;

    public DXFBlock() {
    }

    public Bounds getBounds() {
        Bounds var1 = new Bounds();
        Iterator<DXFEntity> var2 = this.entities.iterator();
        if (var2.hasNext()) {
            while(var2.hasNext()) {
                DXFEntity var3 = var2.next();
                Bounds var4 = var3.getBounds();
                if (var4.isValid()) {
                    var1.addToBounds(var4);
                }
            }
        } else {
            var1.setValid(false);
        }

        return var1;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String var1) {
        this.description = var1;
    }

    public Point getReferencePoint() {
        return this.referencePoint;
    }

    public void setReferencePoint(Point var1) {
        this.referencePoint = var1;
    }

    public void addDXFEntity(DXFEntity var1) {
        this.entities.add(var1);
    }

    public List<DXFEntity> getEntities() {
        return this.entities;
    }

    public Iterator<?> getDXFEntitiesIterator() {
        return this.entities.iterator();
    }

    public String getLayerID() {
        return this.layerID;
    }

    public void setLayerID(String var1) {
        this.layerID = var1;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String var1) {
        this.name = var1;
    }

    public void setDXFDocument(DXFDocument var1) {
        this.doc = var1;

        for (DXFEntity entity : this.entities) {
            entity.setDXFDocument(var1);
        }

    }

    public DXFDocument getDXFDocument() {
        return this.doc;
    }

    public double getLength() {
        double var1 = 0.0D;

        DXFEntity var4;
        for(Iterator<DXFEntity> var3 = this.entities.iterator(); var3.hasNext(); var1 += var4.getLength()) {
            var4 = var3.next();
        }

        return var1;
    }

    public DXFEntity getDXFEntityByID(String var1) {
        DXFEntity var2 = null;
        Iterator<DXFEntity> var3 = this.entities.iterator();

        DXFEntity var4;
        do {
            if (!var3.hasNext()) {
                return var2;
            }

            var4 = var3.next();
        } while(!var4.getID().equals(var1));

        return var4;
    }
}
